import { getCurrentInstance, onMounted, ref } from 'vue';
import { tnNavPage } from '@tuniao/tnui-vue3-uniapp/utils';
import { useSubPageProvide } from '../../../composables';
import type { NavbarRectInfo } from '@tuniao/tnui-vue3-uniapp/components/navbar';
import type { IndexPageOnLoadFunc, IndexPageOnScrollFunc } from '../../../types';
import type { Category } from '@/types/api/category';

import { useScrollTransparentNavbar } from '@/hooks';
import { ColorType } from '@/types/color';

export const useSubPage = () => {
	const instance = getCurrentInstance();
	// 顶部轮播图
	const swiperData = ref<string[]>([
        'https://wechatapppro-1252524126.cdn.xiaoeknow.com/appDrL11SLy3991/image/b_u_5e72c3bbc3f6b_myKIdmDJ/l6xeu3r408ak.jpg?imageMogr2/thumbnail/750x/quality/80|imageMogr2/ignore-error/1',
        'https://wechatapppro-1252524126.cdn.xiaoeknow.com/appDrL11SLy3991/image/b_u_5e72c3bbc3f6b_myKIdmDJ/l4f6kz100u0v.jpg?imageMogr2/thumbnail/750x/quality/80|imageMogr2/ignore-error/1',
        'https://wechatapppro-1252524126.cdn.xiaoeknow.com/appDrL11SLy3991/image/b_u_cm1q6hbjop0v4ep6aom0/b1iv0alu22rulo.jpg?imageMogr2/thumbnail/750x/quality/80|imageMogr2/ignore-error/1',
        'https://wechatapppro-1252524126.cdn.xiaoeknow.com/appDrL11SLy3991/image/b_u_cm1q6hbjop0v4ep6aom0/1qdne3lt3t2wuo.jpg?imageMogr2/thumbnail/750x/quality/80|imageMogr2/ignore-error/1',
        'https://wechatapppro-1252524126.cdn.xiaoeknow.com/appDrL11SLy3991/image/b_u_cm1q6hbjop0v4ep6aom0/hsvky6lu22sevb.jpg?imageMogr2/thumbnail/750x/quality/80|imageMogr2/ignore-error/1'
		// 'https://resource.tuniaokj.com/images/swiper/ad2.jpg',
		// 'https://resource.tuniaokj.com/images/swiper/ad3.jpg',
		// 'https://resource.tuniaokj.com/images/swiper/ad4.jpg',
		// 'https://resource.tuniaokj.com/images/swiper/ad5.jpg'
	]);

	// 热门分类
	const hotCategoryData = ref<Category[]>([
		{
			id: '1',
			name: '信息价',
			icon: 'cute',
			backgroundColor: {
				type: ColorType.select,
				value: '#3c7efe'
			},
			url: '/home-page/information-price/index'
		},
		{
			id: '2',
			name: '市场价',
			icon: 'cute',
			backgroundColor: {
				type: ColorType.select,
				value: '#2be9bb'
			},
			url: '/home-page/market-price/index'
		},
		{
			id: '3',
			name: '工程文库',
			icon: 'cute',
			backgroundColor: {
				type: ColorType.select,
				value: '#e93c32'
			},
			url: '/home-page/project-library/index'
		},
		{
			id: '4',
			name: '项目案例',
			icon: 'cute',
			backgroundColor: {
				type: ColorType.select,
				value: '#ffa929'
			},
			url: '/home-page/project-example/index'
		}
	]);
	// 热门分类
	const hotCategoryData2 = ref<Category[]>([
		{
			id: '5',
			name: '计价依据',
			icon: 'cute',
			backgroundColor: {
				type: ColorType.select,
				value: '#8447fb'
			},
			url: '/home-page/valuation-basis/index'
		},
		{
			id: '6',
			name: '专业课程',
			icon: 'cute',
			backgroundColor: {
				type: ColorType.select,
				value: '#93df35'
			},
			url: '/home-page/professional-courses/index'
		},
		{
			id: '7',
			name: '行业信息',
			icon: 'cute',
			backgroundColor: {
				type: ColorType.select,
				value: '#008ad2'
			},
			url: '/home-page/tuniao-ecology/index'
		},
		{
			id: '8',
			name: '项目信息',
			icon: 'cute',
			backgroundColor: {
				type: ColorType.select,
				value: '#008ad2'
			},
			url: '/home-page/tuniao-ecology/index'
		}
	]);

	// 通知数据
	const noticeData = ref<string[]>(['Demo案例APP全新上线，欢迎大家前来访问111', 'Demo案例APP全新上线，欢迎大家前来访问222', 'Demo案例APP全新上线，欢迎大家前来访问333']);

	// 广告胶囊
	// const adCapsuleData = ref<string>('https://resource.tuniaokj.com/images/swiper/capsule1.png');
	const adCapsuleData = ref<string>('https://wechatapppro-1252524126.cdn.xiaoeknow.com/appDrL11SLy3991/image/compress/750240l2soemfa0vet.jpeg');
	
	// 名师直播
	const hotCaseData = ref<string[]>([
		'https://wechatapppro-1252524126.cdn.xiaoeknow.com/appDrL11SLy3991/image/b_u_5e72c3bbc3f6b_myKIdmDJ/lfj24pyi0omq.jpg?imageView2/w/1050/q/100/rq/100|imageMogr2/ignore-error/1',
		'https://wechatapppro-1252524126.cdn.xiaoeknow.com/appDrL11SLy3991/image/b_u_5e72c3bbc3f6b_myKIdmDJ/lf94sz8y0nhu.jpg?imageView2/w/1050/q/100/rq/100|imageMogr2/ignore-error/1',
		'https://wechatapppro-1252524126.cdn.xiaoeknow.com/appDrL11SLy3991/image/b_u_5e72c3bbc3f6b_myKIdmDJ/lexzalyc0e48.jpg?imageView2/w/1050/q/100/rq/100|imageMogr2/ignore-error/1'
	]);

	const { triggerElementId, navbarOpacity, init: initTransparentScroll, updateTargetTriggerValue, opacityScrollHandle } = useScrollTransparentNavbar(instance);

	onMounted(() => {
		initTransparentScroll();
	});

	// 顶部导航栏初始化完成事件
	const navbarInitFinishHandle = (info: NavbarRectInfo) => {
		updateTargetTriggerValue(info.height);
	};

	// 跳转到关于图鸟页面
	const navAboutPage = () => {
		tnNavPage('/tuniao/about/index');
	};

	// 跳转到搜索页面
	const navSearchPage = () => {
		tnNavPage('/home-page/search/index');
	};

	const onLoad: IndexPageOnLoadFunc = () => {
		// eslint-disable-next-line no-console
		console.log('pageA onLoad');
	};
	const onScroll: IndexPageOnScrollFunc = ({ top }) => {
		opacityScrollHandle(top);
	};

	useSubPageProvide(0, {
		onLoad,
		onScroll
	});

	return {
		triggerElementId,
		navbarOpacity,
		swiperData,
		hotCategoryData,
		hotCategoryData2,
		noticeData,
		adCapsuleData,
		hotCaseData,
		tnNavPage,
		navbarInitFinishHandle,
		navAboutPage,
		navSearchPage
	};
};
